and

 

and is a primitive that can be used to combine two true-or-false statements, known as booleans in the computer world, into a single true-or-false statement such that the result is true if and only if both inputs are true. For instance, if we wanted a turtle to eat if (A) they were hungry and (B) if there was food in their patch, we could say:

if hungry? and food-here? [
  eat
]

In this model, we use and to generate a river down the middle of our world. a patch turns blue if and only if its x coordinate is both to the left of (width / 2) and to the right of - (width / 2), otherwise, it remains a green patch.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the and primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Similar primitives:
if

Conditionally run a command.

Read more
or

checks if either of two conditions is true

Read more
if-else

execute specific code if a condition is true, otherwise, execute other code

Read more
ifelse-value

execute different code for a number of different conditions

Read more
 
Learn another primitive